package com.loveyukari.dao.impl;

import com.loveyukari.dao.YukariConcernDao;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class JdbcYukariConcernDao extends BaseDao implements YukariConcernDao {
    @Override
    public void insert(int authId) {
        String sql = "insert into yukari_concern (auth_id) values(?)";
        this.getJdbcTemplate().update(sql,authId);
    }

    @Override
    public void delete(int authId) {
        String sql = "delete from yukari_concern where auth_id = ?";
        this.getJdbcTemplate().update(sql,authId);
    }


    @Override
    public Integer selectId(int authId) {
        String sql = "select auth_id from yukari_concern where id = ?";
        List<Integer> list = this.getJdbcTemplate().queryForList(sql, Integer.class, authId);
        if (list.isEmpty()){
            return null;
        } else {
            return list.get(0);
        }
    }

    @Override
    public List<Integer> selectAuthAll() {
        String sql = "select auth_id from yukari_concern order by rank desc";
        return this.getJdbcTemplate().queryForList(sql,Integer.class);
    }

    @Override
    public void updateRank(int authId, int rank) {
        String sql = "update yukari_concern set rank = ? where auth_id = ?";
        this.getJdbcTemplate().update(sql,rank,authId);
    }
}
